/*
 * @lc app=leetcode.cn id=908 lang=typescript
 *
 * [908] 最小差值 I
 */

// @lc code=start
function smallestRangeI(nums: number[], k: number): number {
    let max = -Infinity;
    let min = Infinity;
    for (let i = 0; i < nums.length; i++) {
        const element = nums[i];
        max = Math.max(max, element);
        min = Math.min(min, element);
    }
    const diff = max - min - 2 * k;

    return diff < 0 ? 0 : diff;
}
// @lc code=end
